
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <title>h5支付</title>
  <style>
    html, body {
      margin: 0;
      padding: 0;
      width: 100%;
      height: 100%;
      background: #f1f1f1;
    }
    .app {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      width: 80%;
      height: 10rem;
      margin: auto;
      background-color: #fff;
      border-radius: 1rem;
      display: none;
    }
    .app-dl {
      margin: 0;
      padding: 0;
      text-align: center;
    }
    .app-dt {
      margin: 0;
      padding: 0;
      line-height: 3.5;
      font-weight: bold;
    }
    .app-dd {
      margin: 0;
      padding: 0;
      border-top: 1px solid #f1f1f1;
      line-height: 3;
      cursor: pointer;
    }
    #btnSuccess {
      color: green;
    }
    #btnError {
      color: red;
    }
  </style>
</head>
<body>
  <div id="app" class="app">
    <dl class="app-dl">
      <dt class="app-dt">请确定微信支付是否已完成</dt>
      <dd class="app-dd" id="btnSuccess">已完成支付</dd>
      <dd class="app-dd" id="btnError">支付失败</dd>
    </dl>
  </div>
  <script>
    var queryString = getQuery();
    var toUrl = queryString.url;

    if (toUrl) {
      var toPaySuccessUrl = queryString.ok;

      history.replaceState(null, '', location.origin + '/h5pay.html?ok=' + encodeURIComponent(toPaySuccessUrl))
      location.href = toUrl;
    } else {
      var toPaySuccessUrl = queryString.ok;
      var toPayErrorUrl = toPaySuccessUrl.replace('pay-success.html', 'pay-fail.html');
      // 修改支付失败跳转路径
      if(queryString.version==='3.0.0'){
        toPayErrorUrl = toPaySuccessUrl.replace('pay-success', 'cashier');
      }
     

      document.getElementById('app').style.display = 'block'
      document.getElementById('btnSuccess').onclick = function() {
        location.href = toPaySuccessUrl
      }

      document.getElementById('btnError').onclick = function() {
        location.href = toPayErrorUrl
      }
    }

    /**
     * [getQuery 获取url传入参数]
     * @return {[type]} [description]
     */
    function getQuery() {
      var url = location.search; //获取url中"?"符后的字串
      var rtv = {};

      if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        var queryGroup = str.split("&");

        queryGroup.forEach(query => {
          let [ key, val ] = query.split("=");
          rtv[key] = decodeURIComponent(val);
        });
      }
      return rtv;
    }
  </script>
</body>
</html>
